package com.zkingsoft.actions.admin;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.model.AdvertisementPosition;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.AdvertisementPositionService;

/**
 * @author dingchuan
 * @date 2016-07-15 11:19
 * 广告位Controller
 */
@Controller
@RequestMapping(value = "admin/advertisementPosition")
public class AdvertisementPositionController extends BaseController{

	@Resource
	private AdvertisementPositionService currentService;
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(AdvertisementPosition advertisementPosition, PaginationVO pageVo) {
		return showList(currentService, advertisementPosition, pageVo);
	}
   	
	/**
	 * 新增或者修改页面
	 */   	
   	@RequestMapping(value = "/addOrModify")
   	@RemoveRequestToken
	public @ResponseBody AjaxResult addOrModify(AdvertisementPosition advertisementPosition) {
   		//没有图片的话给一张默认图片
   		if(advertisementPosition.getImage()==null || advertisementPosition.getImage().equals("")){
   			advertisementPosition.setImage("");
   		}
		if (advertisementPosition.getId() != null) {
			return modify(currentService, advertisementPosition, "广告位");
		} else {
			advertisementPosition.setCreatetime(new Date());
			return add(currentService, advertisementPosition, "广告位");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
   	@RequestMapping(value = "/editForm")
   	@SaveRequestToken
	public String editForm(Long id) {
		AdvertisementPosition advertisementPosition;
		if (id != null) {
			advertisementPosition = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", advertisementPosition);
		}
		return "admin/adPositionManage-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}
  
}